﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace Infrastructure.Extensions
{
    /// <summary>
    /// tcpclient扩展
    /// </summary>
    public static class TcpClientExtenisons
    {
        /// <summary>
        /// socket是否在线
        /// </summary>
        /// <param name="c">客户端连接</param>
        /// <returns></returns>
        public static bool IsOnline(this TcpClient c)
        {
            return !((c.Client.Poll(1000, SelectMode.SelectRead) && (c.Client.Available == 0)) || !c.Client.Connected);
        }
    }
}
